home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWMenu / Include / FWPullDM.h < prev   
Encoding:
Text File  |  1995-11-08  |  10.2 KB  |  320 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPullDM.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWPULLDM_H
  11. #define FWPULLDM_H
  12.  
  13. #ifndef FWMNUITM_H
  14. #include "FWMnuItm.h"
  15. #endif
  16.  
  17. #ifndef FWRESACC_H
  18. #include "FWResAcc.h"
  19. #endif
  20.  
  21. // ----- ODUtil Includes -----
  22.  
  23. #ifndef FWORDCOL_H
  24. #include "FWOrdCol.h"
  25. #endif
  26.  
  27. #if FW_LIB_EXPORT_PRAGMAS
  28. #pragma lib_export on
  29. #endif
  30.  
  31. //========================================================================================
  32. //    Forward Class Declarations
  33. //========================================================================================
  34.  
  35. class FW_CLASS_ATTR FW_CMenuBar;
  36. class FW_CLASS_ATTR FW_CPrivOrderedCollection;
  37. class FW_CLASS_ATTR ODPart;
  38. class FW_CLASS_ATTR ODMenuBar;
  39.  
  40. //========================================================================================
  41. //    class FW_CPullDownMenu
  42. //========================================================================================
  43.  
  44. class FW_CLASS_ATTR FW_CPullDownMenu
  45. {
  46. public:
  47.     FW_DECLARE_CLASS
  48.  
  49. //----------------------------------------------------------------------------------------
  50. //    Constructors/Destructors
  51. //
  52. public:
  53.     FW_CPullDownMenu(Environment* ev);
  54.     
  55.     FW_CPullDownMenu(Environment* ev, 
  56.                 const FW_CString& menuTitle);
  57.                 
  58.     FW_CPullDownMenu(Environment* ev, 
  59.                 FW_CResourceFile &resFile,
  60.                 FW_ResourceId resourceId,
  61.                 unsigned long stringId);
  62.                 
  63.     FW_CPullDownMenu(Environment* ev, 
  64.                 FW_CReadableStream& archive);
  65.     
  66.     virtual ~FW_CPullDownMenu();
  67.     
  68. //----------------------------------------------------------------------------------------
  69. //    New API
  70. //
  71. public:
  72.     //----- Getters/setters -----
  73.     ODMenuID                GetMenuID(Environment* ev) const;
  74.     const ODPlatformMenu&    GetPlatformMenu(Environment* ev) const;
  75.     
  76.     FW_Boolean                IsAttachedToMenuBar(Environment* ev) const;
  77.     FW_CMenuBar*            GetMenuBar(Environment* ev) const;
  78.     
  79.     void                    DisableAll(Environment* ev);
  80.     void                    EnableAll(Environment* ev);
  81.     
  82.     unsigned long            CountItems(Environment* ev) const;
  83.     
  84.     ODCommandID                GetCommandID(Environment* ev, short position) const;        // position : one-based
  85.  
  86.     //----- Adding items -----
  87.     void                    AppendTextItem(Environment* ev, 
  88.                                 const FW_CString& text,
  89.                                 ODCommandID commandID,
  90.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  91.                                 
  92.     void                    AppendTextItem(Environment* ev,
  93.                                 FW_CResourceFile &resFile,
  94.                                 FW_ResourceId resourceId,
  95.                                 unsigned long id,                                
  96.                                 ODCommandID commandID,
  97.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  98.                                 
  99.     void                    InsertTextItem(Environment* ev, 
  100.                                 const FW_CString& text,
  101.                                 ODCommandID commandID,
  102.                                 short afterItem,
  103.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  104.                                 
  105.     void                    InsertTextItem(Environment* ev,
  106.                                 FW_CResourceFile &resFile,
  107.                                 FW_ResourceId resourceId,
  108.                                 unsigned long id,                                
  109.                                 ODCommandID commandID,
  110.                                 short afterItem,
  111.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  112.                                 
  113.     void                    InsertTextItemAfterCommand(Environment* ev, 
  114.                                 const FW_CString& text,
  115.                                 ODCommandID commandID,
  116.                                 ODCommandID afterCommand,
  117.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  118.                                 
  119.     void                    InsertTextItemAfterCommand(Environment* ev,
  120.                                 FW_CResourceFile &resFile,
  121.                                 FW_ResourceId resourceId,
  122.                                 unsigned long id,                                
  123.                                 ODCommandID commandID,
  124.                                 ODCommandID afterCommand,
  125.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  126.                                 
  127.     void                    AppendToggleItem(Environment* ev, 
  128.                                 const FW_CString& trueText,
  129.                                 const FW_CString& falseText,
  130.                                 ODCommandID commandID,
  131.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  132.                                             
  133.     void                    AppendToggleItem(Environment* ev,
  134.                                 FW_CResourceFile &resFile,
  135.                                 FW_ResourceId resourceId,
  136.                                 unsigned long trueId,
  137.                                 unsigned long falseId,
  138.                                 ODCommandID commandID,
  139.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  140.  
  141.     void                    InsertToggleItem(Environment* ev, 
  142.                                 const FW_CString& trueText,
  143.                                 const FW_CString& falseText,
  144.                                 ODCommandID commandID,
  145.                                 short afterItem,
  146.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  147.                                             
  148.     void                    InsertToggleItem(Environment* ev,
  149.                                 FW_CResourceFile &resFile,
  150.                                 FW_ResourceId resourceId,
  151.                                 unsigned long trueId,
  152.                                 unsigned long falseId,
  153.                                 ODCommandID commandID,
  154.                                 short afterItem,
  155.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  156.  
  157.     void                    InsertToggleItemAfterCommand(Environment* ev, 
  158.                                 const FW_CString& trueText,
  159.                                 const FW_CString& falseText,
  160.                                 ODCommandID commandID,
  161.                                 ODCommandID afterCommand,
  162.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  163.                                             
  164.     void                    InsertToggleItemAfterCommand(Environment* ev,
  165.                                 FW_CResourceFile &resFile,
  166.                                 FW_ResourceId resourceId,
  167.                                 unsigned long trueId,
  168.                                 unsigned long falseId,
  169.                                 ODCommandID commandID,
  170.                                 ODCommandID afterCommand,
  171.                                 FW_MenuKey menuKey = FW_kNoKeyEquivalent);
  172.  
  173.     void                    AppendSubMenu(Environment* ev,
  174.                                 FW_CPullDownMenu* adoptSubMenu);
  175.                                 
  176.     void                    InsertSubMenu(Environment* ev,
  177.                                 FW_CPullDownMenu* adoptSubMenu,
  178.                                 short afterItem);
  179.                                 
  180.     void                    InsertSubMenuAfterCommand(Environment* ev,
  181.                                 FW_CPullDownMenu* adoptSubMenu,
  182.                                 ODCommandID afterCommand);
  183.                                 
  184.     void                    AppendSeparator(Environment* ev);
  185.         
  186.     void                    InsertSeparator(Environment* ev,
  187.                                 short afterItem);
  188.         
  189.     void                    InsertSeparatorAfterCommand(Environment* ev,
  190.                                 ODCommandID afterCommand);
  191.         
  192.     //----- Removing items -----
  193.     void                    RemoveItem(Environment* ev, 
  194.                                 short position);
  195.                                 
  196.     //----- Archiving -----
  197.     static void*            Read(FW_CReadableStream& archive);
  198.     static void             Write(FW_CWritableStream& archive, const void* thePullDownMenu);
  199.     void                     Flatten(Environment* ev, FW_CWritableStream& archive) const;
  200.  
  201.     // ----- Parent Menu Item
  202.     FW_CMenuItem*            GetParentMenuItem(Environment* ev) const;
  203.     void                    SetParentMenuItem(Environment* ev, 
  204.                                 FW_CMenuItem* menuItem);
  205.  
  206.     // ----- Adopt Items
  207.     void                    AdoptMenuItemLast(Environment* ev, 
  208.                                 FW_CMenuItem* menuItem);
  209.     void                    AdoptMenuItemAfter(Environment* ev, 
  210.                                 FW_CMenuItem* menuItem,
  211.                                 short afterItem);
  212.                                                     
  213.  
  214. //----------------------------------------------------------------------------------------
  215. //    Internal use only
  216. //
  217. public:
  218.     void                     PrivInitialize(Environment* ev, const FW_CString& menuTitle);
  219.  
  220.     FW_CPullDownMenu*        PrivFindMenuWithID(Environment* ev, ODMenuID menuID) const;
  221.     
  222.  
  223.     FW_CMenuItem*            PrivGetMenuItem(Environment* ev, ODCommandID commandID) const;
  224.  
  225.     void                    PrivAttachedToMenuBar(Environment* ev, 
  226.                                 FW_CMenuBar* menuBar, 
  227.                                 ODMenuID beforeID);
  228.     void                    PrivDetachedFromMenuBar(Environment* ev,
  229.                                 FW_CMenuBar* menuBar);
  230.  
  231.     void                    PrivAttach(Environment* ev, 
  232.                                 FW_CMenuBar* menuBar);
  233.     void                    PrivDetach(Environment* ev, 
  234.                                 FW_CMenuBar* menuBar);
  235.             
  236.     short                    PrivAcquireMenuID(Environment* ev, 
  237.                                 FW_CMenuBar* menuBar);
  238.     void                    PrivRelinquishMenuID(Environment* ev);
  239.     
  240. //----------------------------------------------------------------------------------------
  241. //    Data Members
  242. //
  243. private:
  244.     ODMenuID            fMenuID;            // if -1 the menu is not attached
  245.     ODPlatformMenu        fPlatformMenu;
  246.     FW_CMenuBar*        fMenuBar;            // if NULL the menu is not attached
  247.     FW_CPrivOrderedCollection*    fItems;
  248.     FW_CMenuItem*        fParentMenuItem;    // NULL if not a submenu
  249. };
  250.  
  251. //----- Archiving -----
  252. FW_FUNC_ATTR FW_CReadableStream& operator>>(FW_CReadableStream& archive, FW_CPullDownMenu*& object);
  253. FW_FUNC_ATTR FW_CWritableStream& operator<<(FW_CWritableStream& archive, const FW_CPullDownMenu* object);
  254.  
  255. //========================================================================================
  256. //    FW_CPullDownMenu inlines
  257. //========================================================================================
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    FW_CPullDownMenu::GetMenuID
  261. //----------------------------------------------------------------------------------------
  262. inline ODMenuID FW_CPullDownMenu::GetMenuID(Environment* ev) const
  263. {
  264.     return fMenuID;
  265. }
  266.  
  267. //----------------------------------------------------------------------------------------
  268. //    FW_CPullDownMenu::GetPlatformMenu
  269. //----------------------------------------------------------------------------------------
  270. inline const ODPlatformMenu& FW_CPullDownMenu::GetPlatformMenu(Environment* ev) const
  271. {
  272.     return fPlatformMenu;
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. //    FW_CPullDownMenu::IsAttachedToMenuBar
  277. //----------------------------------------------------------------------------------------
  278. inline FW_Boolean FW_CPullDownMenu::IsAttachedToMenuBar(Environment* ev) const
  279. {
  280.     return fMenuBar != NULL;
  281. }
  282.  
  283. //----------------------------------------------------------------------------------------
  284. //    FW_CPullDownMenu::GetMenuBar
  285. //----------------------------------------------------------------------------------------
  286. inline FW_CMenuBar* FW_CPullDownMenu::GetMenuBar(Environment* ev) const
  287. {
  288.     return fMenuBar;
  289. }
  290.  
  291. //----------------------------------------------------------------------------------------
  292. //    FW_CPullDownMenu::GetParentMenuItem
  293. //----------------------------------------------------------------------------------------
  294. inline FW_CMenuItem* FW_CPullDownMenu::GetParentMenuItem(Environment* ev) const
  295. {
  296.     return fParentMenuItem;
  297. }
  298.  
  299. //----------------------------------------------------------------------------------------
  300. //    FW_CPullDownMenu::SetParentMenuItem
  301. //----------------------------------------------------------------------------------------
  302. inline void FW_CPullDownMenu::SetParentMenuItem(Environment* ev, FW_CMenuItem* menuItem)
  303. {
  304.     fParentMenuItem = menuItem;
  305. }
  306.  
  307. //----------------------------------------------------------------------------------------
  308. //    FW_CPullDownMenu::CountItems
  309. //----------------------------------------------------------------------------------------
  310. inline unsigned long FW_CPullDownMenu::CountItems(Environment* ev) const
  311. {
  312.     return fItems->Count();
  313. }
  314.  
  315. #if FW_LIB_EXPORT_PRAGMAS
  316. #pragma lib_export off
  317. #endif
  318.  
  319. #endif
  320.